package com.bxd.baodan.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.bxd.baodan.App;
import com.bxd.baodan.R;
import com.bxd.baodan.adapter.ViewHolder;
import com.bxd.baodan.app.JsonApi;
import com.bxd.baodan.item.SchemeBean.DataBean.SchemeBean_;
import com.bxd.baodan.util.GlideUtil;
import com.bxd.baodan.util.NetUtil;
import com.umeng.analytics.MobclickAgent;

import java.lang.reflect.Type;
import java.util.List;

public class SchemeAllActivity extends BaseListActivity<SchemeBean_> {

    @Override
    protected int getActivityLayout() {
        return R.layout.pull_refresh_layout_no_divider;   //0
    }

    @Override
    protected void preDone() {
        setActionBarTitle("精选方案");  // 1
        autoRefresh();  //2
        refView.setMode(PullToRefreshBase.Mode.DISABLED);

    }

    @Override
    protected Type getTypeToken() {
        return new TypeToken<List<SchemeBean_>>() {
        }.getType();   //3
    }

    @Override
    protected int getItemLayout() {
        return R.layout.all_scheme_item;   //4
    }

    @Override
    protected void setNetUtil() {
        //5
        netUtil = new NetUtil(this, JsonApi.SCHEME_LIST);
        netUtil.setParams("type", "0");
    }

    @Override
    protected void convert(ViewHolder holder, final SchemeBean_ item) {
        // 7

        GlideUtil.loadImage(context, item.image_l, (ImageView) holder.getView(R.id.iv));
        ((TextView) holder.getView(R.id.title)).setText(item.title);
        ((TextView) holder.getView(R.id.description)).setText(item.description);
        holder.getView(R.id.main).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               MobclickAgent.onEvent(App.getContext(), "v6_1_3_SY_fagd_fnxq ");
                ((BaseActivity) context).openActivity(WebViewPager.class, new String[]{"startUrl"}, new String[]{item.url});
            }
        });
    }


    @Override
    protected String getArrayStr(String json_data) {

        //6
        return "list";
    }
}
